let arr1 = [1, 1, 2]
let arr2 = [1, 1, 3]


let k = 2
let idx1 = 0, idx2 = 0
let sum = 0


while(idx1 < k && idx2 < k){
    sum += arr1[idx1] + arr2[idx2]
    if(arr1[idx1] + arr2[idx2 + 1] >= arr2[idx2] + arr1[idx1 + 1]){
        idx1++
    }else{
        idx1++
    }
}

console.log(sum)